const install = (Vue, vm) => {

	const name = [
		//必填
		{
			required: true,
			message: '请输入姓名',
			trigger: ['change', 'blur'],
		},
		//汉字
		{
			// 自定义验证函数，见上说明
			validator: (rule, value, callback) => {
				// 上面有说，返回true表示校验通过，返回false表示不通过
				return vm.$u.test.chinese(value);
			},
			message: '姓名必须为中文',
			// 触发器可以同时用blur和change
			trigger: ['change', 'blur'],
		},
		//长度
		{
			validator: (rule, value, callback) => {
				return vm.$u.test.rangeLength(value, [2, 5]);
			},
			message: '姓名长度在3到5个字符',
			trigger: ['change', 'blur'],
		}
	]

	const mobile = [
		{
			required: true,
			message: '请输入手机号',
			trigger: ['change', 'blur'],
		},
		{
			validator: (rule, value, callback) => {
				return vm.$u.test.mobile(value);
			},
			message: '手机号码不正确',
			trigger: ['change', 'blur'],
		}
	]

	const verifyCode = [
		{
			required: true,
			message: '请输入验证码',
			trigger: ['change', 'blur'],
		},
		{
			validator: (rule, value, callback) => {
				return vm.$u.test.code(value);
			},
			message: '验证码不正确',
			trigger: ['change', 'blur'],
		}
	]

	const idCard = [
		//必填
		{
			required: true,
			message: '请输入身份证号',
			trigger: ['change', 'blur'],
		},
		//身份证号
		{
			validator: (rule, value, callback) => {
				return vm.$u.test.idCard(value);
			},
			message: '身份证号不正确',
			trigger: ['change', 'blur'],
		}
	]


	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	vm.$u.cusTest = {
		name,
		mobile,
		verifyCode,
		idCard,
	};
}

export default {
	install
}
